import { loginAPI } from '@/api/user'
// 调用接口方法，使用cookie进行本地储存和vuex储存
import { setToken, getToken, removeToken } from '@/utils/auth'
export default {
  namespaced: true,
  state: {
    token: getToken() || ''
  },
  mutations: {
    setToken(state, newToken) {
      state.token = newToken
      // 设置方法
      setToken(newToken)
    },
    removeToken(state) {
      // 清空本地储存的token
      state.token = ''
      // 清空cookie里面的token
      removeToken('form_key')
    }
  },
  actions: {
    async doLogin(stoer, data) {
      const res = await loginAPI(data)
      console.log(res)
      stoer.commit('setToken', res.data.token)
    }

  }
}
